﻿using System;
using System.Globalization;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml.Serialization;


namespace PSGQuickTimeTracker.DataModel
{
	/// <summary>
	/// Simple object that represents a Quick Task Tracker task entry.
	/// </summary>
	public class QTTask
	{
		private string _qtt_Duration;

		#region Properties
        //
        // XML Node Attributes
		//
        [XmlAttribute("User")]
		public string QTT_User { get; set; }

		[XmlAttribute("TaskType")]
		public string QTT_TaskType { get; set; }

        //
        // XML Node Elements
        //
		[XmlElement("Category")]
		public string QTT_Category { get; set; }

		[XmlElement("Date")]
		public string QTT_Date { get; set; }

		[XmlElement("Description")]
		public string QTT_Description { get; set; }

		[XmlElement("Duration")]
		public string QTT_Duration
		{
			get { return _qtt_Duration; }
			set
			{
				_qtt_Duration = value;
				if (value != "" && value != null)
				{   
                    // Get int 
					var tmpVal = decimal.Parse(value.Substring(0, value.IndexOf(" ")).Trim());
					if (value.Contains("h"))
					{                        
						QTT_DurationMinutes = (int)decimal.Round((tmpVal * 60), 0);
						QTT_DurationHours = decimal.Round(tmpVal, 2);
					}
					else
					{
						QTT_DurationMinutes = (int)decimal.Round(tmpVal, 0);
						QTT_DurationHours = decimal.Round((tmpVal / 60), 2);
					}
				}
				else
				{
					QTT_DurationMinutes = 0;
					QTT_DurationHours = 0;
				}
			}
		}

		[XmlElement("DurationMinutes", type:typeof(int))]
		public int QTT_DurationMinutes { get; set; }

		[XmlElement("DurationHours", type:typeof(decimal))]
		public decimal QTT_DurationHours { get; set; }

		#endregion



		public QTTask()
		{
		}

		

		public QTTask(string user, string date, string category, string duration, string desc, string taskType)
		{
			QTT_User        = user;
            QTT_Date        = date;
			QTT_Category    = category;
			QTT_Duration    = duration;
			QTT_Description = desc;
			QTT_TaskType    = taskType;
		}


	}

}
